package com.dhcc.sds.qzj.service.impl;

import com.dhcc.sds.qzj.entity.DrgsInnerReportData;
import com.dhcc.sds.qzj.service.IDrgsInnerReportDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DrgsInnerReportDateServiceImpl implements IDrgsInnerReportDataService {
    @Autowired
    private List<MongoTemplate> mongoTemplates;
    @Override
    public List<DrgsInnerReportData> findByDiseaseType(String diseaseType) {
        List<DrgsInnerReportData> drgsInnerReportDataList= new ArrayList<>();
        Query query = new Query(Criteria.where("diseaseTypes").is(diseaseType));
        for (MongoTemplate mongoTemplate : mongoTemplates) {
            List<DrgsInnerReportData> drgsInnerReportSubDataList = mongoTemplate.find(query, DrgsInnerReportData.class);
            drgsInnerReportDataList.addAll(drgsInnerReportSubDataList);
        }
        return drgsInnerReportDataList;
    }

    @Override
    public DrgsInnerReportData findByCaseId(String diseaseType) {
        return null;
    }

    @Override
    public List<DrgsInnerReportData> findByReportTime(String startDate, String endDate) {
        List<DrgsInnerReportData> drgsInnerReportDataList = new ArrayList<>();
        Query query = new Query(Criteria.where("reportTime").gte(startDate).lt(endDate));
        for (MongoTemplate mongoTemplate : mongoTemplates) {
            List<DrgsInnerReportData> drgsInnerReportSubDataList = mongoTemplate.find(query, DrgsInnerReportData.class);
            drgsInnerReportDataList.addAll(drgsInnerReportSubDataList);
        }
        return drgsInnerReportDataList;
    }
}
